package com.wanshi.cloud.service.impl;


import com.wanshi.cloud.Page;
import com.wanshi.cloud.client.OrderClient;
import com.wanshi.cloud.entity.Orders;
import com.wanshi.cloud.entity.User;
import com.wanshi.cloud.mapper.UserMapper;
import com.wanshi.cloud.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 顽石教育-www.wanshi.com
 * @since 2021-09-03
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
     @Autowired
     private OrderClient orderClient;
    @Override
    public User findbyid(String id) {
        User user = this.getById(id);

        //查询给user所有的订单
        List<Orders> orders = orderClient.findbyuserid(id);

        user.setOrders(orders);
        return user;
    }

    @Override
    public List<User> findalll() {

        return this.list();

    }

    @Override
    public Page findbypage(Integer page, Integer size) {

        Page <User> page1 = new Page<>(page, size);
        this.page(page1);
        return page1;
    }
}
